include config.mk

SUBMAKES := $(wildcard ./src/*/Makefile)
SUBDIRS  := $(foreach _,${SUBMAKES},$(call dir,${_}))
TARGETS  := $(foreach _,${SUBDIRS},${_}$(call notdir,$(abspath ${_})))

SUBMAKE_TARGETS := uninstall clean \
		   test_compilers \
		   clang-tidy-check clang-format-check check-all

.PHONY: all
all: ${TARGETS}

define submake
.PHONY: ${1}
${1}: ${2}
	{ : \
	; set -ue \
	; for d in $${SUBDIRS} \
	; do $$(MAKE) -C "$$$${d}" ${1} \
	; done \
	}
endef

${TARGETS}:
	${MAKE} -C $(call dir,${@})

$(eval $(call submake,install,${TARGETS}))

$(foreach _,${SUBMAKE_TARGETS},$(eval $(call submake,${_},)))

.PHONY: metalang
metalang:
	${MAKE} -C include ${@}
